package interfaz.admin;


import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class PanelInicialAdmin extends JPanel{

	public VentanaAdmin ventanaAdmin;
	private JLabel fondo;

	private javax.swing.JButton bLogin;
	private javax.swing.JLabel lPsw;
	private javax.swing.JLabel lUsuario;
	private javax.swing.JPasswordField tfPsw;
	private javax.swing.JTextField tfUsuario;
	private PanelConexionesAdmin conexionAdmin;
	private String usuario;
	private String psw;

	public PanelInicialAdmin(){

		lPsw = new javax.swing.JLabel();
		lUsuario = new javax.swing.JLabel();
		tfUsuario = new javax.swing.JTextField();
		tfPsw = new javax.swing.JPasswordField();
		bLogin = new javax.swing.JButton();
		conexionAdmin = new PanelConexionesAdmin(this);
		fondo = new JLabel();

		setVisible(true);

		setLayout(null);

		lPsw.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
		lPsw.setForeground(new java.awt.Color(255, 255, 255));
		lPsw.setText("Usuario");
		add(lPsw);
		lPsw.setBounds(240, 230, 90, 30);

		lUsuario.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
		lUsuario.setForeground(new java.awt.Color(255, 255, 255));
		lUsuario.setText("Contrase�a");
		add(lUsuario);
		lUsuario.setBounds(240, 300, 90, 30);
		add(tfUsuario);
		tfUsuario.setBounds(350, 230, 190, 30);

		add(tfPsw);
		tfPsw.setBounds(350, 300, 190, 30);

		bLogin.setText("Entrar");
		bLogin.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent evt) {
				comprobarAdmin(evt);
			}

			public void mouseEntered(MouseEvent arg0) {

			}

			public void mouseExited(MouseEvent arg0) {

			}

			public void mousePressed(MouseEvent arg0) {	   }

			public void mouseReleased(MouseEvent arg0) {	}
		});
		add(bLogin);
		bLogin.setBounds(360, 380, 90, 30);

		fondo.setIcon(new ImageIcon("src/resources/fondoAdmin.jpg"));
		add(fondo);
		fondo.setBounds(0, 0, 800, 600);
	}
	

	private void comprobarAdmin(MouseEvent evt) {
		usuario = tfUsuario.getText();
		psw = tfPsw.getText();
		System.out.println("USUARIO: "+usuario+"  "+"PSW: "+psw);

		//PRUEBA. Hay que controlarlo con el servidor!!
		if(usuario.equals("admin") && psw.equals("admin")){
			this.setVisible(false);
			ventanaAdmin.getContentPane().add(conexionAdmin, 0);
			conexionAdmin.setVisible(true);
		}else{
			if(!usuario.equals("admin")){
				JOptionPane.showMessageDialog(null, "Error! Usuario incorrecto", "Error", JOptionPane.ERROR_MESSAGE);
			}else{
				if(!psw.equals("admin")){
					JOptionPane.showMessageDialog(null, "Error! Contrase�a incorrecta", "Error", JOptionPane.ERROR_MESSAGE);

				}
			}

		}
	}
	
	

}
